#include <stdint.h>
#include <stdio.h>
#include "riff_wav.h"

int riff_wav_header_pack(WAVE_INFO *info, WAVE_HEADER *header)
{
    header->id[0] = 'R';
    header->id[1] = 'I';
    header->id[2] = 'F';
    header->id[3] = 'F';
    header->size = info->length + 36;
    header->fmt[0] = 'W';
    header->fmt[1] = 'A';
    header->fmt[2] = 'V';
    header->fmt[3] = 'E';

    header->subchunk1.id[0] = 'f';
    header->subchunk1.id[1] = 'm';
    header->subchunk1.id[2] = 't';
    header->subchunk1.id[3] = ' ';
    header->subchunk1.size = 16;
    header->subchunk1.format = info->format;
    header->subchunk1.channel = info->channel;
    header->subchunk1.samplerate = info->samplerate;
    header->subchunk1.blockalign = info->channel * info->bitdepth / 8;
    header->subchunk1.byterate = info->samplerate * header->subchunk1.blockalign;
    header->subchunk1.bitdepth = info->bitdepth;

    header->subchunk2.id[0] = 'd';
    header->subchunk2.id[1] = 'a';
    header->subchunk2.id[2] = 't';
    header->subchunk2.id[3] = 'a';
    header->subchunk2.size = info->length;

    return 0;
}

